* Table A7c Balance and Summary Statistics for attritors
* Sample used to study household outcomes
* Last Updated, Niriksha Shetty 03/31/2016

clear
clear mata
clear matrix
set maxvar 20000
set more off

pwd
cap cd c(`pwd')

estimates clear

use "../dta/reduced-form-master.dta", clear

* dropping people temporarily added to the sample
drop if add_sample_w2==1 | add_sample_w5==1  

* individual marketing treatments
local uniqinst "assigned_risk_ws_2008 discount_2008 rebate_50percentoff rebate2_1free rebate3_1free flyer_hyv bdmperc_2009 fourbdmperc_2009 disc4game_2009 bdmperc_2010 fourbdmperc_2010 disc4game_2010 assigned_risk_ws_2010 assigned_video_test assigned_drought_flyer assigned_subsidies_flyer assigned_loan bdmperc_2011 fourbdmperc_2011 disc4game_2011 bdmperc_2012 fourbdmperc_2012 disc4game_2012 bdmperc_2013 fourbdmperc_2013 disc4game_2013"  /* sewaT peerT assigned_risk_ws_2011 assigned_risk_ws_2012 assigned_risk_ws_2013 mrkt_allnegative mrkt_poslang mrkt_posimg*/

foreach var of varlist `uniqinst' {
	replace `var' = 0 if `var'==.
	replace `var' = 0 if wave==0
	}

foreach var of varlist `uniqinst' {
	replace `var' = 0 if treat_year==0
}

* identifying attritors, did not complete survey or reported missing consumption or income
gen EP_A=0
replace EP_A=1 if ex_post_balp==0

bys id : egen ever_attrit=max(EP_A)

local vars "w_real_cons w_real_food_exp w_real_events_exp w_real_gifts_out w_real_nonfood_exp w_real_durables_exp w_real_income w_real_gifts_in w_real_sav w_real_lent w_real_borrow food_sufficiency_child fladder_std outlook_std control_std "

qui estpost summarize `vars' if mkt_year==2005 & EP_A==1
est sto A 
qui estpost summarize `vars' if originaltvillage==1 & mkt_year==2005 & EP_A==1& EP_A==1
est sto B 
qui estpost summarize `vars' if firstt_2007==1 & mkt_year==2005 & EP_A==1
est sto C
qui estpost summarize `vars' if Tvillage==0 & mkt_year==2005 & EP_A==1
est sto D
qui estpost summarize `vars' if firstt_2009==1 & mkt_year==2008 & EP_A==1
est sto E
esttab A B C D E using "../output/sum-a7c.csv", cells("mean(fmt(2))" replace sd(par fmt(2))) nolabel noabbrev title("Summary statistics") collabels("Mean") mtitle("Control" "Treat") nonum replace 

local vars "w_real_cons w_real_food_exp w_real_events_exp w_real_gifts_out w_real_nonfood_exp w_real_durables_exp w_real_income w_real_gifts_in w_real_sav w_real_lent w_real_borrow food_sufficiency_child fladder_std outlook_std control_std "

tempvar tmp
gen `tmp' = .
foreach var of local vars {
reg `var' originaltvillage firstt_2007 if mkt_year == 2005 & EP_A==1, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005 & EP_A==1
est sto A
esttab A using "../output/bal-a7c.csv", cells("mean(fmt(2))") label noabbrev collabels("p-value") mtitle("") noobs nonum append
replace `tmp' = .
estimates clear
}
